package com.controller;

import com.common.dto.BaseIdReqDTO;
import com.common.dto.BaseIdsReqDTO;
import com.common.dto.PagingReqDTO;
import com.entity.Repo;
import com.entity.dto.RepoDTO;
import com.entity.dto.request.RepoReqDTO;
import com.service.RepoService;
import com.utils.PageUtils;
import com.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* 题库控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-05-25 13:25
*/
@Api(tags={"题库"})
@RestController
@RequestMapping("/exam/repo")
public class RepoController {

    @Autowired
    private RepoService repoService;

//    @Autowired
//    private QuRepoService quRepoService;

    /**
    * 添加或修改
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "添加或修改")
    @RequestMapping(value = "/save", method = { RequestMethod.POST})
    public R save(@RequestBody RepoDTO reqDTO) {
        repoService.save(reqDTO);
        return R.ok();
    }

    /**
    * 批量删除
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/delete", method = { RequestMethod.POST})
    public R edit(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        repoService.deleteBatchIds(reqDTO.getIds());
        return R.ok();
    }

    /**
    * 查找详情
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "查找详情")
    @RequestMapping(value = "/detail", method = { RequestMethod.POST})
    public R find(@RequestBody BaseIdReqDTO reqDTO) {
        Repo entity = repoService.selectById(reqDTO.getId());
        RepoDTO dto = new RepoDTO();
        BeanUtils.copyProperties(entity, dto);
        return R.ok().put("data", dto);
    }

    /**
    * 分页查找
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "分页查找")
    @RequestMapping(value = "/paging", method = { RequestMethod.POST})
    public R paging(@RequestBody PagingReqDTO<RepoReqDTO> reqDTO) {

        //分页查询并转换
        PageUtils page = repoService.paging(reqDTO);

        return R.ok().put("data", page);
    }

//    /**
//     * 批量操作
//     * @param reqDTO
//     * @return
//     */
//    @ApiOperation(value = "批量操作", notes = "批量加入或从题库移除")
//    @RequestMapping(value = "/batch-action", method = { RequestMethod.POST})
//    public ApiRest batchAction(@RequestBody QuRepoBatchReqDTO reqDTO) {
//
//        //分页查询并转换
//        quRepoService.batchAction(reqDTO);
//        return super.success();
//    }
}
